<template>
  <a-card :bordered="false" :body-style="{'padding-top':'2px', 'padding-left':'0px', 'padding-right':'0px', 'padding-bottom':'0px'}">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <a-table
      ref="table"
      size="middle"
      :scroll="{x:true}"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      class="j-table-force-nowrap"
      @change="handleTableChange">

      <template slot="htmlSlot" slot-scope="text">
        <div v-html="text"></div>
      </template>
      <template slot="imgSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
        <img v-else :src="getImgView(text)" height="25px" alt=""
             style="max-width:80px;font-size: 12px;font-style: italic;"/>
      </template>
      <template slot="fileSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button
          v-else
          :ghost="true"
          type="primary"
          icon="download"
          size="small"
          @click="downloadFile(text)">
          下载
        </a-button>
      </template>

      <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

    </a-table>

    <mdm-user-info-modal ref="modalForm" @ok="modalFormOk"></mdm-user-info-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import MdmUserInfoModal from './modules/MdmUserInfoModal'
import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

export default {
  name: 'MdmUserInfoTable',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    MdmUserInfoModal
  },
  data() {
    return {
      description: '人员信息管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '人员ID',
          align: "center",
          dataIndex: 'userid'
        },
        {
          title: '人员账号',
          align: "center",
          dataIndex: 'username'
        },
        {
          title: '姓名',
          align: "center",
          dataIndex: 'realname'
        },
        {
          title: '机构编码',
          align: "center",
          dataIndex: 'orgCode'
        },
        {
          title: '工作中心',
          align: "center",
          dataIndex: 'workId_dictText'
        },
        {
          title: '租户ID',
          align: "center",
          dataIndex: 'tenantId'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/mdm/userInfo/list",
        delete: "/mdm/userInfo/delete",
        deleteBatch: "/mdm/userInfo/deleteBatch",
        exportXlsUrl: "/mdm/userInfo/exportXls",
        importExcelUrl: "mdm/userInfo/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'userid', text: '人员ID', dictCode: ''})
      fieldList.push({type: 'string', value: 'username', text: '人员账号', dictCode: ''})
      fieldList.push({type: 'string', value: 'realname', text: '姓名', dictCode: ''})
      fieldList.push({type: 'string', value: 'orgCode', text: '机构编码', dictCode: ''})
      fieldList.push({type: 'string', value: 'workId', text: '工作中心', dictCode: 'mdm_work_center,name,id'})
      fieldList.push({type: 'string', value: 'tenantId', text: '租户ID', dictCode: ''})
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>